package com.dcy.quartz.service;

import com.dcy.common.base.service.DcyBaseService;
import com.dcy.common.model.PageModel;
import com.dcy.common.model.PageResult;
import com.dcy.quartz.dao.JobLogDao;
import com.dcy.quartz.model.JobLog;
import com.dcy.quartz.vo.in.JobLogSearchInVO;
import com.dcy.quartz.vo.out.JobLogListOutVO;
import com.dcy.quartz.convert.JobLogConvert;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 定时任务调度日志表 服务实现类
 * </p>
 *
 * @author dcy
 * @since 2021-04-03
 */
@RequiredArgsConstructor
@Service
public class JobLogService extends DcyBaseService {

    private final JobLogDao jobLogDao;
    private final JobLogConvert jobLogConvert = JobLogConvert.INSTANCE;

    /**
     * 获取表格数据
     *
     * @param jobLogSearchInVO
     * @param pageModel
     * @return
     */
    public PageResult<JobLogListOutVO> pageListByEntity(JobLogSearchInVO jobLogSearchInVO, PageModel pageModel) {
        return toPageResult(jobLogDao.pageListByEntity(jobLogConvert.toJobLog(jobLogSearchInVO), pageModel), page -> jobLogConvert.toOutputList(page.getRecords()));
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public Boolean delete(String id) {
        return jobLogDao.removeById(id);
    }


    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public Boolean deleteBatch(List<String> idList) {
        return jobLogDao.removeBatchByIds(idList);
    }

    /**
     * 清空日志
     */
    public void removeJobLog() {
        jobLogDao.deleteJobLog();
    }

    /**
     * 保存
     *
     * @param jobLog
     */
    public void save(JobLog jobLog) {
        jobLogDao.save(jobLog);
    }
}
